package com.littcore.saap.event;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import me.chanjar.weixin.mp.bean.result.WxMpPayCallback;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.littcore.saap.system.biz.ITenantBizService;
import com.littcore.saas.wechat.event.WechatNotifyEvent;
import com.littcore.saas.wechat.event.WechatNotifyEvent.EventType;

public class WechatEventListener {

    private static final Logger logger = LoggerFactory.getLogger(WechatEventListener.class);

    private ITenantBizService tenantBizService;

    public void listen(Object object) {
        if (object instanceof WechatNotifyEvent) {
            WechatNotifyEvent event = (WechatNotifyEvent) object;
            Map detail = (Map) event.getDetail();
            if (event.getEventType().equals(EventType.PAY_RESULT)) {

                try {
                    WxMpPayCallback payResult = new WxMpPayCallback();
                    BeanUtils.populate(payResult, detail);
                    tenantBizService.onPayResult(payResult);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }

    }

}
